/*
 * Copyright 2010 - Jeremie Brebec
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.jb.coinche.client.ui.card.impl;

import org.jb.coinche.client.ui.card.StatusPanel;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.util.Padding;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout.VBoxLayoutAlign;

/**
 * 
 * @author jeremie
 *
 */
public class StatusPanelImpl extends LayoutContainer implements StatusPanel {

	/*
	 * 
	 */
	public StatusPanelImpl() {
		VBoxLayout layout = new VBoxLayout();  
        layout.setPadding(new Padding(5));  
        layout.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER);  
        setLayout(layout);  
	}
	

	/*
	 * (non-Javadoc)
	 * @see org.jb.coinche.client.gui.card.StatusPanel#setStatus(java.lang.String)
	 */
	@Override
	public void setStatus(String status) {
		removeAll();
		
		add( new Html( status ) );
		
		layout();		
	}

	/*
	 * (non-Javadoc)
	 * @see org.jb.coinche.client.gui.card.StatusPanel#setStatus(java.lang.String, java.lang.String, org.jb.coinche.client.gui.card.StatusPanel.ActionHandler)
	 */
	@Override
	public void setStatus(String status, String action, final ActionHandler handler) {
		
		removeAll();
		
		if (status != null)
			add( new Html( status ) );
		
		Button btn = new Button( action );
		btn.addSelectionListener( new SelectionListener<ButtonEvent>() {
			
			@Override
			public void componentSelected(ButtonEvent ce) {
				handler.execute();
			}
		});
		add( btn, new VBoxLayoutData( new Margins(5)) );
		
		layout();
		
	}

}
